package com.service.impl;

import com.constant.Constant;
import com.dao.UserDao;
import com.entity.User;
import com.exception.ServiceException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.UserService;
import com.vo.UserBackVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * date:2021/4/29
 * description:
 * Author:Stargazer
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public User loginBack(User user) {
        User u = userDao.selectByLoginnameAndPassword(user);
        if(u == null){
            throw new ServiceException("用户名/密码错误");
        }
        return u;
    }


    @Override
    public PageInfo<UserBackVo> findBackUser(UserBackVo userBackVo,Integer page) {

        PageHelper.startPage(page, Constant.PAGE_SIZE);
        List<UserBackVo> list = userDao.selectAll(userBackVo);

        return new PageInfo<UserBackVo>(list);
    }

    @Override
    public void modifyBackUser(User user) {
        userDao.modifyBackUser(user);
    }

    @Override
    public User showBackUser(Integer id) {
        return userDao.showBackUser(id);
    }
}
